package com.ysx.search.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ysx.common.pojo.Result;
import com.ysx.core.controller.AbstractCoreController;
import com.ysx.search.dto.SearchDto;
import com.ysx.search.pojo.ApAssociateWords;
import com.ysx.search.service.ApAssociateWordsService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
* <p>
* 联想词表 控制器</p>
* @author ljh
* @since 2021-10-09
*/
@Api(value="联想词表",tags = "ApAssociateWordsController")
@RestController
@RequestMapping("/apAssociateWords")
public class ApAssociateWordsController extends AbstractCoreController<ApAssociateWords> {

    private ApAssociateWordsService apAssociateWordsService;

    //注入
    @Autowired
    public ApAssociateWordsController(ApAssociateWordsService apAssociateWordsService) {
        super(apAssociateWordsService);
        this.apAssociateWordsService=apAssociateWordsService;
    }

    @PostMapping("/searchTen")
    public Result<List<ApAssociateWords>> findByPage(@RequestBody SearchDto searchDto) {

        //List<ApAssociateWords> associateWordsList = apAssociateWordsService.searchV2(searchDto);

        //1.只查询前10条联想词即可 不用展示特别多
        searchDto.setSize(10);
        searchDto.setPage(1);
        Page<ApAssociateWords> apAssociateWordsPage = new Page<ApAssociateWords>(searchDto.getPage(), searchDto.getSize());
        QueryWrapper<ApAssociateWords> queryWrapper = new QueryWrapper<ApAssociateWords>();
        queryWrapper.like("associate_words", searchDto.getKeywords());
        queryWrapper.orderByDesc("created_time");
        IPage<ApAssociateWords> page = apAssociateWordsService.page(apAssociateWordsPage, queryWrapper);

        return Result.ok(page.getRecords());
        //return Result.ok(associateWordsList);
    }

}

